package com.red.star.wechat.data.utils;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FieldUtil {

    /**
     * 返回指定内容
     */
    public static <T> List<T> checkField(List<T> o, String... field) {
        for(T t:o){
            checkField(t,field);
        }
        return o;
    }
    public static <T> T checkField(T o, String... field) {
        Set<String> set = new HashSet<String>();
        for (String s : field) {
            set.add(s);
        }
        Class cls = o.getClass();
        Field[] fields = cls.getDeclaredFields();
        for(int i=0; i<fields.length; i++){
            Field f = fields[i];
            f.setAccessible(true);
            if(set.add(f.getName())) {
                try {
                    f.set(o,null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return o;
    }

}
